<!DOCTYPE html>
<!--管理用户界面-->
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>标签列表</title>
    <link rel="stylesheet" href="tagList.css">
    <script src="jquery-latest.js"></script>
</head>
<body onload="initTime()">

<h4>
    欢迎您：<text th:text="${session.doctorVO.name}"></text>&ensp;
    科室：<text th:text="${session.doctorVO.office}"></text>&ensp;
    权限：<text th:text="${session.doctorVO.role}"></text>
</h4>

<div class="select">
    <a href="/listAllPatient">
        <input type="submit" class="button" value="标签绑定">
    </a>
    <a href="/listAllTags">
        <input type="submit" class="button" value="标签管理">
    </a>
</div>
<hr>

<div class="title">
    <h2 style="font-size: xxx-large">标签列表</h2>
</div>
<div class="list">
    <div>
        <h3 style="display: inline">搜索标签:</h3>
        <form style="display: inline" method="post" action="/getTagByName" enctype="multipart/form-data" id="getTagByName">
            <input type="text" name="tag_name">
            <button>
                <a onclick="document:getTagByName.submit()">搜索</a>   <!--提交-->
            </button>
        </form>
        <button>
            <a href="/listAllTags">重置</a>
        </button>
    </div>
    <p></p>
    <div>
        <h3 style="display: inline">添加标签:</h3>
        <form class="form" method="post" action="/createTag" enctype="multipart/form-data" id="createTag">
            标签名:<input type="text" name="tag_name">
            分组:<select name="tag_group">
            <option th:each="group:${groupList}" th:value="${group.id}" th:text="${group.description}"></option>
                </select>
            <input class="date" type="datetime-local" placeholder="请选择日期" name="tag_start_time" id="tag_start_time" min="0000-00-00T00:00:00" max="9999-12-31T23:59:59" step="1">
            <input class="date" type="datetime-local" placeholder="请选择日期" name="tag_end_time" value="9999-12-31T23:59:59" min="0000-00-00T00:00:00" max="9999-12-31T23:59:59" step="1">
            <!--                <input type="hidden" name="pageFirst" th:value="${pageFirst}">-->
            科室:<select name="tag_office">
            <option th:each="office:${officeList}" th:value="${office.id}" th:text="${office.description}"></option>
                </select>
            分类:<select name="tag_weight">
            <option th:each="weight:${weightList}" th:value="${weight.id}" th:text="${weight.description}"></option>
                </select>
            <input type="hidden" name="oid" th:value="${session.doctor.oid}">
            <input type="hidden" name="role" th:value="${session.doctor.role}">
            <button>
                <a onclick="document:createTag.submit()">提交</a>   <!--提交-->
            </button>
        </form>
        <button>
            <a onclick="getAllids()">筛选</a>   <!--筛选-->
        </button>
        <a th:text="${lt_message}" style="color: red"></a>   <!--总信息-->
    </div>
    <p></p>
    <table class="tag">
        <tr>
            <th>标签id</th>
            <th>名称</th>
            <th>标签分组</th>
            <th>有效期开始时间</th>
            <th>有效期结束时间</th>
            <th>科室</th>
            <th>分类</th>
            <th>修改</th>
            <th>删除</th>
            <th>筛选病人</th>
        </tr>
        <div th:each="tag:${tagList}" >                         <!--遍历-->
            <tr>
                <div>
                    <td th:text="${tag.tag_id}"> </td>
                    <td th:text="${tag.tag_name}"> </td>
                    <td th:switch="${tag.tag_group}">
                        <span th:each="group:${groupList}" th:case="${group.id}" th:text="${group.description}"></span>
                    </td>
                    <td th:text="${tag.tag_start_time}"></td>
                    <td th:text="${tag.tag_end_time}"></td>
                    <td th:switch="${tag.tag_office}">
                        <span th:each="office:${officeList}" th:case="${office.id}" th:text="${office.description}"></span>
                    </td>
                    <td th:switch="${tag.tag_weight}">
                        <span th:each="weight:${weightList}" th:case="${weight.id}" th:text="${weight.description}"></span>
                    </td>
                    <td>
                        <a th:href="@{/getTagById(tag_id=${tag.tag_id}, tag_group=${tag.tag_group}, tag_office=${tag.tag_office},
                         tag_weight=${tag.tag_weight}, oid=${session.doctor.oid}, role=${session.doctor.role})}">修改</a> <!--链接到修改接口-->
                    </td>
                    <td>
                        <a th:href="@{/deleteTagById(tag_id=${tag.tag_id}, tag_group=${tag.tag_group}, tag_office=${tag.tag_office},
                         tag_weight=${tag.tag_weight}, oid=${session.doctor.oid}, role=${session.doctor.role})}" onClick="return confirm('确定删除?');">删除</a> <!--链接到删除接口-->
                    </td>
                    <td>
                        <input type="checkbox" th:value="${tag.tag_id}" name="tag">
                    </td>
                </div>
            </tr>
        </div>
    </table>

    <form method="post" action="/getPatientListByCondition" enctype="multipart/form-data" id="getPatientListByCondition"><!--隐藏提交筛选Id用-->
        <input type="hidden" name="tagList" id="tagList">
    </form>
</div>
<script language="javascript" type="text/javascript">
    function getAllids(){// 获取多选框的值保存至隐藏input
        //得到chekbox对象
        var checkbox = document.getElementsByName("tag");
        //alert("checkbox的长度为："+checkbox.length);
        var id ="";
        //当选中时，拿到它的value值，并拼起来
        //需要注意的是，这样拼出来的id字符串，是以 ","结尾的，所以在使用的时候，应先将 ","去掉，也可在if中做判断
        // 当为最后一个时，拼的时候不加 ","
        for ( var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].checked){
                id = id + checkbox[i].value+",";
            }
        }
        document.getElementById('tagList').value=id;
        document.getElementById("getPatientListByCondition").submit();
    }
    function dateFormat(fmt, date) {// 时间格式化
        let ret;
        const opt = {
            "Y+": date.getFullYear().toString(),        // 年
            "m+": (date.getMonth() + 1).toString(),     // 月
            "d+": date.getDate().toString(),            // 日
            "H+": date.getHours().toString(),           // 时
            "M+": date.getMinutes().toString(),         // 分
            "S+": date.getSeconds().toString()          // 秒
            // 有其他格式化字符需求可以继续添加，必须转化成字符串
        };
        for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            };
        };
        return fmt;
    }
    function initTime(){// onload方法设置新建标签开始时间为当前时间
        document.getElementById('tag_start_time').value=dateFormat("YYYY-mm-ddTHH:MM:SS", new Date());
    }


</script>
</body>
</html>